import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'

const root = process.cwd();
const pathResolve = (pathname: string) => resolve(root, '.', pathname);

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [ vue(), UnoCSS() ],
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  // 模块引入别名
  resolve: {
    alias: [
      {
        find: 'vue-i18n',
        replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
      },
      // @/xxxx => src/xxxx
      {
        find: /@\//,
        replacement: pathResolve('src') + '/',
      },
      // #/xxxx => types/xxxx
      {
        find: /#\//,
        replacement: pathResolve('types') + '/',
      },
    ],
  },
  server: {
    port: 3000,
    open: true,
    hmr: {
      // overlay: true,
      // on_reload: () => {}
    },
    // 可以配置额外的来监听文件变化
    watch: {
      // ignore: []

    }
  }
})
